package org.springboot.base.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springboot.base.MyException;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author ZJL
 * @DateTime 2019年2月8日 上午1:13:11
 * 自定义过滤器
 **/
public class MyFilter implements Filter {
	private String paramName;
	@Value("${com.web.yltd}")
	private String yltd;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("MyFilter init......");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("MyFilter doFilter......");
		HttpServletRequest req = (HttpServletRequest)request;
		String url = req.getRequestURI();
		System.out.println("url==="+req.getRequestURI());
//		if(url.endsWith("demo3")) {
//			throw new MyException("我是错误");
//		}
		System.out.println("paramName==="+this.paramName+"-----com.web.yltd==="+this.yltd);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		System.out.println("MyFilter destroy......");
	}

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public String getYltd() {
		return yltd;
	}

	public void setYltd(String yltd) {
		this.yltd = yltd;
	}

}
